package com.epam.edu.command;

import com.epam.edu.dao.DAOInputMark;
import com.epam.edu.dao.DAOSpecialty;
import com.epam.edu.dao.DAOSubject;
import com.epam.edu.db.ConnectionPool;
import com.epam.edu.entity.InputMark;
import com.epam.edu.entity.Specialty;
import com.epam.edu.entity.Subject;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class InputMarksCommand implements Command {
    @Override
    public String perform(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException, NoSuchAlgorithmException {
        ConnectionPool pool = null;
        Connection connection = null;
        try {
            ConnectionPool.init();
            pool = ConnectionPool.getInstance();
            connection = pool.takeConnection();
            List<InputMark> inputMarks = DAOInputMark.selectAll(connection);
            request.setAttribute("inputMarks", inputMarks);
            List<Specialty> specialties = DAOSpecialty.selectAll(connection);
            request.setAttribute("specialties", specialties);
            List<Subject> subjects = DAOSubject.selectAll(connection);
            request.setAttribute("subjects", subjects);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "/WEB-INF/jsp/admin/catalogInputMarks.jsp";
    }
}
